﻿@using MVCExtension.Pager
@model IEnumerable<FTchinaMVC.Models.Book>

@{
    ViewBag.Title = "Index";
}

<table class="tableBorder">
    <tr align="center" valign="middle">
        <th colspan="2">管 理
        </th>
    </tr>
    <tr>
        <td>操作
        </td>
        <td>

            @Html.ActionLink("添加", "create", null,
            new Dictionary<string, object>() {   
{ "class", "easyui-linkbutton" },  
{"data-options", "plain:true,iconCls:'icon-add'"} ,
            })
            <a class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-reload'" href="#" onclick="Refresh()">刷新</a>
            @Html.ActionLink("导出Excel", "excel", null,
            new Dictionary<string, object>() {   
{ "class", "easyui-linkbutton" },  
{"data-options", "plain:true,iconCls:'icon-output'"} ,
{"model","false"}
            })
            <input type='checkbox' id='checkall' name='checkall' />选择
           <a class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-cancel'" 
               onclick="GroupDo('del')" href="#">删除</a>

        </td>
    </tr>
</table>

<table class="tableBorder" id="gvList">
    <thead>
        <tr>
            <th></th>
            <th>
                @Html.DisplayNameFor(model => model.BookName)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Author)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Publisher)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Price)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Remark)
            </th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model)
        {
            <tr>
                <td>
                    <input type='checkbox' id='ids' name='ids' value='@item.BookID' /></td>
                <td>
                    @Html.DisplayFor(modelItem => item.BookName)

                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Author)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Publisher)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Price)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Remark)
                </td>
                <td>
                    @Html.ActionLink(" ", "Edit", new RouteValueDictionary(new { id = item.BookID }),
                        new Dictionary<string, object>  {   
							{ "class", "easyui-linkbutton" },  
							{"data-options", "plain:true,iconCls:'icon-edit'"} ,
                            {"title","编辑" }})&nbsp;
                    @Html.ActionLink(" ", "Details", new RouteValueDictionary(new { id = item.BookID }),
                        new Dictionary<string, object>  {   
							{ "class", "easyui-linkbutton" },  
							{"data-options", "plain:true,iconCls:'icon-note'"} ,
                            {"title","查看" }})&nbsp;
                    @Html.ActionLink(" ", "Delete", new RouteValueDictionary(new { id = item.BookID }),
                        new Dictionary<string, object>  {   
							{ "class", "easyui-linkbutton" },                             
							{"data-options", "plain:true,iconCls:'icon-cancel'"} ,
                            {"title","删除" }})
                </td>
            </tr>
        }
    </tbody>

</table>

@*@Html.Pager((PagedList<FTchinaMVC.Models.Book>)Model,
 new PagerOptions
 {
     CssClass = "pager",
     PageIndexParameterName = "id",
     MorePagerItemWrapperFormatString = "<li>{0}</li>",
     CurrentPagerItemWrapperFormatString = "<li class='p_current'>{0}</li>",
     NumericPagerItemWrapperFormatString = "<li>{0}</li>",
     NavigationPagerItemWrapperFormatString = "<li>{0}</li>",
     AlwaysShowFirstLastPageNumber = true,
     ShowPageIndexBox = true,
     PageIndexBoxType = PageIndexBoxType.TextBox,
     PageIndexBoxWrapperFormatString = "{0}",
     GoToPageSectionWrapperFormatString = "<li>{0}</li>",
     ShowGoButton = false,
     ShowFirstLast = false,
     SeparatorHtml = "",
 })*@

@Html.Pager((int)ViewBag.ItemsCount, (int)ViewBag.PageSize, (int)ViewBag.PageIndex, "index", "book",
 new PagerOptions
 {
     CssClass = "pager",
     PageIndexParameterName = "id",
     MorePagerItemWrapperFormatString = "<li>{0}</li>",
     CurrentPagerItemWrapperFormatString = "<li class='p_current'>{0}</li>",
     NumericPagerItemWrapperFormatString = "<li>{0}</li>",
     NavigationPagerItemWrapperFormatString = "<li>{0}</li>",
     AlwaysShowFirstLastPageNumber = true,
     ShowPageIndexBox = true,
     PageIndexBoxType = PageIndexBoxType.TextBox,
     PageIndexBoxWrapperFormatString = "{0}",
     GoToPageSectionWrapperFormatString = "<li>{0}</li>",
     ShowGoButton = false,
     ShowFirstLast = false,
     SeparatorHtml = "",
 }, "Default", null, null)


<div id="results" class="hidden"></div>
@section scripts {
    <script src="/Scripts/easyui/jquery.easyui.min.js"></script>
    <link href="/Scripts/easyui/themes/default/linkbutton.css" rel="stylesheet" />
    <link href="/Scripts/easyui/themes/icon.css" rel="stylesheet" />
    <script src="http://cloud.github.com/downloads/ericmmartin/simplemodal/jquery.simplemodal.1.4.3.min.js"></script>

    <script type="text/javascript" type="text/javascript">
        $(function () {
            $("#gvList").tablesorter();
            $("#gvList th").css("cursor", "pointer");
            TableColorDefault("gvList");
            $(".easyui-linkbutton").click(function () {
                ShowModel($(this).attr("href"), $(this).attr("model"));
                return false;
            });

            $("#checkall").click(function () {

                if (this.checked) {
                    $("input[name='ids']").each(function () { this.checked = true; });
                } else {
                    $("input[name='ids']").each(function () { this.checked = false; });
                }
            });

        })
        //批量操作
        function GroupDo(optype) {
            var chk_value = '';
            $('input[name="ids"]:checked').each(function () {
                chk_value = $(this).val() + "," + chk_value;
            });//获取选中的项目
            if (chk_value.length > 0) {
                var url = '/@ViewBag.ControllerName/GroupProcess';
                $.ajax({
                    url: url,
                    type: "POST",
                    data: { ids: chk_value, optype: 'del' },
                    cache: false,
                    success: function (html) {
                        alert(html);
                    }
                });
                location.href = "/@ViewBag.ControllerName/index/@ViewBag.PageIndex";
            }
            else {
                alert("请至少选择一项");
            }
        }
    </script>

}
